/*
 * @Author: gao_m3
 * @Date: 2020-12-08 08:43:18
 * @LastEditors: zhong_m
 * @LastEditTime: 2022-11-22 10:58:20
 * @Descripttion: 
 */
// import Cookies from 'js-cookie'
import * as types from './stateTypes'
import storage from '@/utils/storage'
import defaultSettings from '@/config'
import { SAAS_TYPE } from '@/config/enums'
import { appInfos } from '@/config/microapp/subapps'
import Vue from 'vue'

const { captchaType, realTimePush, socketType, maxReconnect, reconnectInterval,
  openRegister, behaviorAnalysis, developerMode, i18n, dataMode, HTTPMethodOverride, responseEncrypt,
  requestEncrypt, hierarchicalAuth, saas, CLIENT, CLIENT_SECRET, TENANT, multiPortal, mainApp, subApp } = defaultSettings
const state = {
  [types.SIDE_BAR]: {
    // opened: Cookies.get( 'sidebarStatus' ) ? !!+Cookies.get( 'sidebarStatus' ) : true,
    opened: true,
    withoutAnimation: false
  },
  [types.DEVICE]: 'desktop',
  [types.SIDE_BAR_LOGO]: true,
  [types.DATA_SAFE]: {
    isUrlAuth: false,
    requestEncrypt, // 请求加密
    responseEncrypt, // 响应加密
    HTTPMethodOverride, // PUT请求代理
  },
  [types.LATEST_CLIENT_CONFIG]: {},
  [types.INTERFACE_CONFIG]: {},
  [types.LOGIN_STRATEGY]: { captchaType },
  [types.ACCOUNT_CONFIG]: {},
  [types.WATERMARK_CONFIG]: {},
  [types.ADVANCED_CONFIG]: {
    realTimePush, socketType, maxReconnect, reconnectInterval,
    openRegister, behaviorAnalysis, i18n, hierarchicalAuth
  },
  [types.DATA_MODE]: dataMode,
  [types.LANG]: {},
  [types.VISITED_VIEWS]: [],
  [types.CACHED_VIEWS]: [],
  [types.USER]: storage.getObject('user'),
  [types.HAS_UNREAD_MESSAGE]: false,
  [types.RECEIVED_MESSAGE]: false,
  [types.ENUM]: {},
  [types.ROUTES]: [],
  [types.PERMISSION]: {},
  [types.BUTTONS]: [],
  [types.PORTALS]: [],
  [types.PORTAL]: storage.getObject('portal'),
  [types.AUTH_PORTAL]: storage.getObject('current_auth_portal'),
  [types.CLIENT_NAME]: '',
  [types.CURRENT_LANG]: storage.get('lang_config') || '',
  [types.WEBSOCKET_POOL]: [],
  [types.PERMISSION_QUEUE]: new Set(),
  [types.DEVELOPER_FLAG]: developerMode && sessionStorage.getItem('developerFlag') === '1',


  [types.CLIENT_CONFIG]: {
    tenantId: storage.getObject('client_config').tenantId || TENANT,
    clientId: storage.getObject('client_config').clientId || CLIENT,
    clientSecret: storage.getObject('client_config').clientSecret || CLIENT_SECRET,
    multiPortal: storage.getObject('client_config').multiPortal || multiPortal,
    tenantMode: !saas ? SAAS_TYPE.NOT_SAAS : (storage.getObject('client_config').tenantId || TENANT == TENANT ? SAAS_TYPE.MAIN : SAAS_TYPE.TENANT),
  },

  [types.QIAN_KUN_STATUS]: {
    isSubApp: subApp,
    isMainApp: mainApp,
    isQianKun: window.__POWERED_BY_QIANKUN__,
    appName: Vue.prototype.$appName,
    appBasePath: Vue.prototype.$appBasePath
  },

  [types.SUB_APP_LIST]: mainApp ? (appInfos ?? []) : []

}

export default state